﻿using S7.Net.Types;
using System.ComponentModel;

namespace Api.Shared.Model.Yanji
{
    public class DbData : INotifyPropertyChanged
    {
        private string str_R = string.Empty;
        private string str_S = string.Empty;
        private bool robComplete;

        [S7String(S7StringType.S7String, 200)]
        public string Str_R
        {
            get => str_R;
            set
            {
                if (str_R != value)
                {
                    str_R = value;
                    if (value != string.Empty)
                    {
                        NotifyPropertyChanged(nameof(Str_R));
                    }


                }
            }
        }



        [S7String(S7StringType.S7String, 200)]
        public string Str_S
        {
            get => str_S;
            set
            {
                if (str_S != value)
                {
                    str_S = value;
                    if (value != string.Empty)
                    {
                        NotifyPropertyChanged(nameof(Str_S));
                    }
                }
            }
        }

        /// <summary>
        /// 机器人自动状态
        /// </summary>
        public bool AutoStatus { get; set; }

        /// <summary>
        /// 心跳
        /// </summary>
        public bool HeartBeat { get; set; }

        /// <summary>
        /// Send发送指令(读)
        /// </summary>
        public bool DataSend { get; set; }

        /// <summary>
        /// 发送区不为空(读)
        /// </summary>
        public bool SendCharIsNotNull { get; set; }

        /// <summary>
        /// 接收区发生错误(读)
        /// </summary>
        public bool ReciveError { get; set; }

        public bool RobComplete
        {
            get => robComplete;
            set
            {
                if (robComplete != value)
                {

                    if (robComplete == false && value == true)
                    {
                        NotifyPropertyChanged(nameof(RobComplete));
                    }
                    robComplete = value;
                }
            }
        }


        public event PropertyChangedEventHandler? PropertyChanged;


        private void NotifyPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
